package tech.yqyl.solo.processor;

import tech.yqyl.solo.BlogInfo;
import tech.yqyl.solo.BlogProcessor;

import java.util.ArrayList;
import java.util.List;

/**
 * @className: AggregationProcessor
 * @description:
 * @author: caoyangjie
 * @date: 2024/9/3
 **/
public class AggregationProcessor extends AbstractProcessor implements BlogProcessor {
    private List<BlogProcessor> processors = new ArrayList<>();

    /**
     * 构造对象
     * @param config 元信息配置
     */
    public AggregationProcessor(MetaConfig config) {
        super(config);
        // 将 博客处理成 不包含各种 前置头，后置脚本 的源文件
        processors.add(new TitleHeadProcessor().setMetaConfig(config));
        processors.add(new BlogHeadProcessor().setMetaConfig(config));
        processors.add(new BlogImageProcessor().setMetaConfig(config));
        processors.add(new Img2GiteeProcessor().setMetaConfig(config));
        processors.add(new LocalPath2WebSiteProcessor().setMetaConfig(config));
        processors.add(new CopyRightProcessor().setMetaConfig(config));
    }

    @Override
    public boolean filter() {
        return true;
    }

    @Override
    public void process(BlogInfo blog) {
        if( !processors.isEmpty() ) {
            for( int i=0; i< processors.size(); i++) {
                BlogProcessor processor = processors.get(i);
                if( processor.filter() ) {
                    processor.process(blog);
                }
            }
        }
    }
}
